package com.ruoyi.coupons.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.coupons.domain.Coupon;
import com.ruoyi.coupons.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/coupon")
public class CouponController extends BaseController {

    @Autowired
    private CouponService couponService;
    /**
     * 查询所有发售的优惠券
     */
    @GetMapping("/list")
    public TableDataInfo getList(){

        IPage<Coupon> page= new Page<>();
        List<Coupon> list = couponService.list(page,null);
        return getDataTable(list);
    }


    /**
     *删除优惠券
     */
    @PutMapping("/qg")
    public AjaxResult qg(int memberId,int couponId){
        return toAjax(couponService.removeById(couponId));
    }

    /**
     * 获取优惠券限购数量
     */
    @GetMapping("/couponNum")
    public AjaxResult getLimt(int couponId){
        return success(couponService.getLimit(couponId));
    }
}
